<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>

    <!--引入Vue和axios-->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <script src="js/common.js"></script>
</head>
<body>
<div id="myDiv">

</div>
<script type="text/javascript">
    new Vue({
        el:"#myDiv",
        mounted(){
            //解析参数上
            let url = location.href;
            let paramObj = parseUrlParams2Obj(url);
            //封装请求参数
            let param = {"code":paramObj.code};
            //发送微信登录验证
            this.$http.post("/login/wechat",param)
                .then(result=>{
                    result = result.data;
                    if(result.success){//已经绑定，免密登录成功
                        alert("登录成功");
                        //1.将token和登录信息存入localStorage
                        let {token,logininfo} = result.resultObj;
                        localStorage.setItem("token",token);
                        localStorage.setItem("logininfo",JSON.stringify(logininfo));
                        //2.跳转到首页，并显示登录信息
                        location.href="index.html";
                    }else{//定位到绑定页面
                        let binderUrl="http://bugtracker.itsource.cn/binder.html"+result.resultObj;
                        //没有绑定，跳转到绑定页面
                        location.href=binderUrl;
                    }
                })
                .catch(result=>{
                    alert("系统异常!");
                })
        }
    })

</script>
</body>
</html>